package starfire.gui.defaultModelAndRenderer;

import java.io.*;

import java.awt.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.table.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author zzzhc.starfire@gmail.com
 * @version 1.0
 */

public class DefaultFSTableRenderer
    extends javax.swing.table.DefaultTableCellRenderer {
  static FileSystemView fsv = FileSystemView.getFileSystemView();
  static Icon dirIcon = null;
 // static Icon fileIcon = null;

  public DefaultFSTableRenderer()
  {
    super();
    if (dirIcon==null)
    {
      try
      {
        File f = new File(".").getCanonicalFile();
         dirIcon = fsv.getSystemIcon(f);

      /*  fileIcon = new ImageIcon(
            starfire.gui.defaultModelAndRenderer.DefaultFSTableRenderer.class.
            getResource("file.gif"));
          */
      }catch (Exception e){}
    }
  }

  public Component getTableCellRendererComponent(JTable table, Object value,
                                                 boolean isSelected,
                                                 boolean hasFocus,
                                                 int row, int column) {
    if (column == 0) {
      //this.setFont(new Font("dialog", 0, 14));
      File f = (File) (table.getModel().getValueAt(row, column));
      if (! (f instanceof starfire.ftp.FtpFile)) {
        this.setIcon(fsv.getSystemIcon(f));
        this.setText(fsv.getSystemDisplayName(f));
      }
      else
      {
        if (f.isDirectory())
          setIcon(dirIcon);
        else
        {
          setIcon(IconCollection.getIcon(f));
        }
        this.setText(f.getName());
      }
      return this;
    }
    else {
      isSelected=hasFocus=false;
    }
    return super.getTableCellRendererComponent(table, value, isSelected,
                                               hasFocus,
                                               row, column);
  }

}
